package net.sppan.base.dao;

import net.sppan.base.entity.Department;
import net.sppan.base.entity.Employee;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface IDepartmentDao {

    @Insert("INSERT INTO `base`.`tb_department`(`department_name`, `department_desc`, `location`, `principal`) VALUES " +
            "(#{departmentName}, #{departmentDesc}, #{location}, #{principal})")
    int savaDepartment(Department department);

    @Select("select id,department_name as departmentName,department_desc as departmentDesc,location,principal from tb_department")
    List<Department> getDepartmentList();

    @Select("select id,department_name as departmentName from tb_department")
    List<Department> gegetAllDepartments();

    @Select("\n" +
            "SELECT\n" +
            "\tid AS id,\n" +
            "\tdepartment_name AS departmentName,\n" +
            "\tdepartment_desc AS departmentDesc,\n" +
            "\tlocation,\n" +
            "\tprincipal \n" +
            "FROM\n" +
            "\ttb_department \n" +
            "WHERE\n" +
            "\tid = #{id} limit 1")
    Department getDepartment(Integer id);

    @Update("UPDATE tb_department \n" +
            "SET department_name = #{departmentName},\n" +
            "department_desc = #{departmentDesc},\n" +
            "location = #{location},\n" +
            "principal = #{principal} \n" +
            "WHERE\n" +
            "\tid = #{id}")
    int updateDepartment(Department department);

    @Delete(" delete from tb_department where id = #{id}")
    int deleteDepartment(Integer id);
}
